<?php
/* @var $this ProductController */
/* @var $model Product */

$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'资迅管理'=>array($this->pre_module_url.'/news/admin'),
	'推荐位管理'=>array('newsrecommend'),
	'添加推荐资讯'
);
?>
<div class="pro_filter c_f">
		<?php $form=$this->beginWidget('CActiveForm', array(
			'action'=>Yii::app()->createUrl($this->route,array('zpoid'=>Yii::app()->request->getParam('zpoid'))),
			'method'=>'get',
		)); ?>
			<label class="">选择类目：</label>
			<span id="catagory">
				<select name="Product[cateid1]" class="level_1 s_ipt w_120" id="dataProductIndustryId1" ></select>
				<select name="Product[cateid2]" class="level_2 s_ipt w_120" id="dataProductIndustryId2"></select>
				<select name="Product[cateid3]" class="level_3 s_ipt w_120" id="dataProductIndustryId3" ></select>
			</span>
			<label class="">发布者：</label>
			<?php echo $form->dropDownList($model,'author_type',News::model()->getAuthorType(),array('class'=>'s_ipt w_120'))?>
			<?php echo CHtml::textField('News[zne_title]',empty($model->zne_title)?'输入信息标题关健字':$model->zne_title,array('class'=>'t_ipt w_170','onfocus'=>"if (value =='输入信息标题关健字'){value =''}",'onblur'=>"if (value ==''){value='输入信息标题关健字'}"))?>
			<button class="mem_bgx mem_btn01" type="submit" name="">查找</button>
		<?php $this->endWidget(); ?>
</div>
<div class="recommend_box"> 
    <div class="hd mem_bgx">设置显示时间</div>
    <ul class="form_list">
        <li><span class="tit">开始时间：</span> <?php echo CHtml::textField('start',date('Y-m-d',time()),array('onclick'=>"WdatePicker()"))?> </li>
        <li><span class="tit">结束时间：</span> <?php echo CHtml::textField('end','',array('onclick'=>"WdatePicker()"))?> </li>
    </ul>
    <div class="hd mem_bgx">选择推荐资讯</div>
    <table class="list_table list_table2" width="100%" cellpadding="0" cellspacing="0">
        <tr class="bgcolor">
            <th width="">标题</th>
            <th width="45%">发布时间</th>
            <th width="22%">操作</th>
        </tr>
        <?php $list = $this->beginWidget('zii.widgets.CListView', array(
                            'dataProvider'=>$model->search(),
                            'itemView'=>'_addrecommendnewsview',
                            'template'=>'',
                            'viewData'=>array('ids'=>$ids),
                        )); ?>
        <?php $list->renderItems();?>
        <tr class="foot">
            <td colspan="3"><?php $list->renderPager();?></td>
        </tr>
        <?php $this->endWidget();?>
    </table>
</div>

<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script> 
<script language="javascript">
	//推荐产品
	function recommend(zpoid,zpid){
		var start = $('#start').val();
		var end   = $('#end').val();
		$.ajax({
			type: "POST",
			url: "/manage/positions/dorecommendnewsajax",
			dataType:"json",
			data: "zpoid="+zpoid+"&zpid="+zpid+"&start="+start+"&end="+end,
			success: function(data){
				switch(data.code){
					case 1: //alert( "推荐提示：推荐成功！");
					$('#recommend'+data.zpid).hide();
					$('#recommended'+data.zpid).show();
					break;
					case 2: alert( "推荐提示：时间设置错误，请设置正确的开始和结束时间！");
					break;
					case 3: alert( "推荐提示：内容已满！");
					break;
					case 4: alert( "推荐提示：内容已推荐");
					break;
					case 5: alert( "推荐提示：产品不存在或不可推荐！");
					break;
					case 6: alert( "推荐提示：推荐位不存在！");
					break;
					case 7: alert( "推荐提示：推荐失败！");
					break;
					case 8: alert( "推荐提示：参数错误，请重试！");
					break;
					default:;
					break;
				}	 
		   }
		});
	}
	//取消推荐
	function unRecommend(zpoid,zpid){
		$.ajax({
			type: "POST",
			url: "/manage/positions/unrecommendnewsajax",
			dataType:"json",
			data: "zpoid="+zpoid+"&zpid="+zpid,
			success: function(data){
				switch(data.code){
					case 1: //alert( "操作提示：取消成功！");
					$('#recommend'+data.zpid).show();
					$('#recommended'+data.zpid).hide();
					break;
					case 2: alert( "该内容不存在！");
					break;
					default:;
					break;
				}	 
		   }
		});
	}
</script>

<script type="text/javascript" src="/js/multi_select.js"></script>
<script type="text/javascript">
$.getJSON('/cache/GetNewsCat',function(json){
	var options	= {data	: json};
	var loc = new multi_select(options);
	loc.bind('#catagory .level_1','<?php if(!empty($model->newscat)) echo ($model->newscat->znc_patentid==0)?$model->newscat->znc_id:(($model->newscat->znc_topid==0)?$model->newscat->znc_patentid:$model->newscat->znc_topid)?>');
	loc.bind('#catagory .level_2','<?php if(!empty($model->newscat)) echo ($model->newscat->znc_patentid==0)?'':(($model->newscat->znc_topid==0)?$model->newscat->znc_id:$model->newscat->znc_patentid)?>');
	loc.bind('#catagory .level_3','<?php if(!empty($model->newscat)) echo ($model->newscat->znc_patentid==0)?'':(($model->newscat->znc_topid==0)?'':$model->newscat->znc_patentid)?>');
});
//载入页面显示分类
$(document).ready(function(){
	if($('.level_2').find('option').length<2){
		$('.level_2').hide();
		$('.level_1').attr('name','News[znc_id]');
		$('.level_2').attr('name','');
		$('.level_3').attr('name','');
	}else{
		$('.level_2').show();
		$('.level_1').attr('name','');
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}
	if($('.level_3').find('option').length<2){
		$('.level_3').hide();
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}else{
		$('.level_3').show();
		$('.level_2').attr('name','');
		$('.level_3').attr('name','News[znc_id]');
	}
});

//选行分类 ，链动隐藏
$('.level_1').bind('blur',function(){
	if($('.level_2').find('option').length<2){
		$('.level_2').hide();
		$('.level_1').attr('name','News[znc_id]');
		$('.level_2').attr('name','');
		$('.level_3').attr('name','');
	}else{
		$('.level_2').show();
		$('.level_1').attr('name','');
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}
	$('.level_3').hide();
});
$('.level_2').bind('blur',function(){
	if($('.level_3').find('option').length<2){
		$('.level_3').hide();
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}else{
		$('.level_3').show();
		$('.level_2').attr('name','');
		$('.level_3').attr('name','News[znc_id]');
	}
});
</script>